package cn.yunhe.insurance.controller;


import cn.yunhe.insurance.entity.Insurcate;
import cn.yunhe.insurance.service.CountService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 刘宜展
 * @date 2018/9/17 14:28
 */

@RestController
@RequestMapping("/count")
public class CountController {
    @Resource
    private CountService countService;

    @RequestMapping("/toCountBefore")
    public ModelAndView toCountBefore() {
        return new ModelAndView("countBefore");
    }

    @RequestMapping("/BeforetoAfter")
    public ModelAndView BeforetoAfter() {
        ModelAndView mv = new ModelAndView();
       /* List<String> list = new ArrayList<String>();
        list.clear();
        list.add("0FE26AD26E11406A937CDB2095FD585B");
        list.add("73c0662eb986441696f13163afe600ed");
        list.add("AC4E1D5968C34B5CA7356B3F1EE58B33");
        List<Insurcate> insurcateList = countService.findInsurcatesByManyId(list);
        int num=0;
        for (Insurcate insurcate : insurcateList) {
            num+=(insurcate.getMininsur()+insurcate.getMaxinsur())/2*insurcate.getComrate()*0.1;

        }
        mv.addObject("num",num);
        mv.addObject("list", insurcateList);*/
        mv.setViewName("countAfter");
        return mv;
    }

    @RequestMapping("/toCountAfter")
    public Map toCountAfter(Integer fangan) {
        ModelAndView mv = new ModelAndView();
        Map map=new HashMap();

        List<String> list = new ArrayList<String>();

         if (fangan == 1||fangan==0 ) {
            list.clear();
            list.add("0FE26AD26E11406A937CDB2095FD585B");
            list.add("73c0662eb986441696f13163afe600ed");
            list.add("AC4E1D5968C34B5CA7356B3F1EE58B33");
            List<Insurcate> insurcateList = countService.findInsurcatesByManyId(list);
            BigDecimal bg = new BigDecimal("0");
            int num=0;
            for (Insurcate insurcate : insurcateList) {
                num+=(insurcate.getMininsur()+insurcate.getMaxinsur())/2*insurcate.getComrate()*0.1;

            }
            map.put("num",num);
            map.put("insurcateList",insurcateList);

        }else if (fangan==2){
            list.clear();
            list.add("5ef0df8026ad4449979270d011950a13");
            list.add("935816D1BA4348889E1BC634A9EF378D");
            List<Insurcate> insurcateList = countService.findInsurcatesByManyId(list);

            BigDecimal bg = new BigDecimal("0");
            int num=0;
            for (Insurcate insurcate : insurcateList) {
                num+=(insurcate.getMininsur()+insurcate.getMaxinsur())/2*insurcate.getComrate()*0.1;

            }
            map.put("num",num);
            map.put("insurcateList",insurcateList);

        }else if(fangan==3){
            list.clear();
            list.add("73c0662eb986441696f13163afe600ed");
            list.add("5ef0df8026ad4449979270d011950a13");
            List<Insurcate> insurcateList = countService.findInsurcatesByManyId(list);
            BigDecimal bg = new BigDecimal("0");
            int num=0;
            for (Insurcate insurcate : insurcateList) {
                num+=(insurcate.getMininsur()+insurcate.getMaxinsur())/2*insurcate.getComrate()*0.1;

            }
            map.put("num",num);
            map.put("insurcateList",insurcateList);
        }
        return map;
    }

}


